package com.yzg.executors;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author misterWei
 * @create 2020年06月13号:02点43分
 * @mailbox forcontinue@163.com
 */
@Slf4j(topic = "c.SingleMain")
public class SingleMain {

    public static void main(String[] args) {
        /**
         * 当前的线程数只有1个,并且能够保证这个1个不会被改变  FinalizableDelegatedExecutorService
         */
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        executorService.execute(()->{
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("|1");
        });
        executorService.execute(()->{
            executorService.shutdown();
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("|2");
        });
    }
}
